package com.javasm.transfer.orderTransfer;

import com.javasm.domin.entity.goodsEntity.GdBrand;
import com.javasm.domin.entity.goodsEntity.GdColour;
import com.javasm.domin.entity.goodsEntity.GdGoods;
import com.javasm.domin.entity.goodsEntity.GdType;
import com.javasm.domin.entity.orderEntity.B2cOrderGoods;
import com.javasm.domin.entity.orderEntity.B2cShoppingcart;
import com.javasm.domin.vo.base.BaseVo;
import com.javasm.domin.vo.orderVo.OrderGoodVo;
import com.javasm.domin.vo.orderVo.OrderShoppingVo;
import com.javasm.mapper.goodsMapper.GdBrandMapper;
import com.javasm.mapper.goodsMapper.GdColourMapper;
import com.javasm.mapper.goodsMapper.GdGoodsMapper;
import com.javasm.mapper.goodsMapper.GdTypeMapper;
import com.javasm.transfer.base.BaseTransfer;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.List;

/**
 * @Author：liyangsong
 * @Version：1.0
 * @Date：2021/11/27-16:31
 * @Since:jdk1.8
 * @Description:
 */

@Component
public class OrderShoppingTranfer extends BaseTransfer<B2cShoppingcart,OrderShoppingVo> {
    @Resource
    private GdGoodsMapper goodsMapper;
    @Resource
    private GdBrandMapper gdBrandMapper;
    @Resource
    private GdColourMapper gdColourMapper;
    @Resource
    private GdTypeMapper gdTypeMapper;


    public List<OrderShoppingVo> setString(List<B2cShoppingcart> b2cShoppingcartList) {
        //将B2cOrderGoods转成orderGoodVo
        List<OrderShoppingVo> b2cShoppingcarts = super.toVO(b2cShoppingcartList);

        for (int i = 0; i < b2cShoppingcarts.size(); i++) {
            B2cShoppingcart b2cShoppingcart = b2cShoppingcartList.get(i);
            Integer id = b2cShoppingcart.getId();
            GdGoods gdGoods = goodsMapper.selectById(id);
            //根据品牌id得到对象
            Integer brandId = b2cShoppingcart.getBrandId();
            GdBrand gdBrand = gdBrandMapper.selectById(brandId);
            //根据颜色id得到颜色
            Integer colorId = b2cShoppingcart.getColourId();
            GdColour gdColour = gdColourMapper.selectById(colorId);
            //根据类型id得到类型
            Integer typeId = b2cShoppingcart.getTypeId();
            GdType gdType = gdTypeMapper.selectById(typeId);
            //转义赋值
            OrderShoppingVo orderShoppingVo = b2cShoppingcarts.get(i);
            orderShoppingVo.setGoodsName(gdGoods == null ? "" : gdGoods.getGoodsName());
            orderShoppingVo.setBrandId(gdBrand == null ? "" : gdBrand.getBrandName());
            orderShoppingVo.setColourId(gdColour == null ? "" : gdColour.getColourName());
            orderShoppingVo.setTypeId(gdType == null ? "" : gdType.getTypeName());
        }
        return b2cShoppingcarts;
    }
}
